class MyArray<T>//泛型类
{
    public T[] obj=(T[]) new Object[5];//定义一个泛型数组

    public T getObj(int pos) {
        return this.obj[pos];
    }

    public void setObj(int pos,T val) {
        obj[pos]=val;
    }
}
public class Test {

    public static void main(String[] args) {
        MyArray<Integer> myArray=new MyArray<Integer>();//指定整数类型的
        myArray.setObj(0,1);
        myArray.setObj(1,5);
        myArray.setObj(2,8);
        int d=myArray.getObj(0);
        int a=myArray.getObj(1);
        System.out.println(d);
        System.out.println(a);
        System.out.println("========================");
        MyArray<String> myArray1=new MyArray<String>();
        myArray1.setObj(1,"zhangsan");
        myArray1.setObj(2,"lisi");
        myArray1.setObj(3,"bit");
        String ret=myArray1.getObj(1);
        String str=myArray1.getObj(2);
        System.out.println(ret);
        System.out.println(str);
    }
}
